﻿using VCards.Models;
using VCards.Types;

namespace VCards.Processors;

public static class AnniversaryProcessor
{
    public static string Serialize(VCard vcard)
    {
        if(vcard.Anniversary == null)
        {
            return string.Empty;
        }

        //Only vCard 4.0 supports ANNIVERSARY property
        if (vcard.Version != VCardVersion.V4)
        {
            return string.Empty;
        }

        return DateTimeProcessor.Serialize(vcard.Anniversary, "ANNIVERSARY", vcard.Version);
    }


    public static void Parse(Token token, ref VCard vcard)
    {
        string value = token.Values[0];
        if (string.IsNullOrWhiteSpace(value))
        {
            return;
        }

        var date = DateTimeProcessor.Parse(value);
        vcard.Anniversary = date;
    }
}